home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 3.1 / SGI EnlightenDSM 3.1.iso / SCO5X / EMD / bin / e_rm_audit_events < prev    next >
Text File  |  1999-04-16  |  3KB  |  202 lines

  1. #!/bin/sh
  2. #  Copyright (c) 1990-1999 Enlighten Software Solutions, Inc.
  3. #             -- All Rights Reserved --
  4.  
  5. OSNAME=`uname -s`
  6. EMDDIR=`egrep "emd_dir=" /etc/enlighten | cut "-d=" -f2 - `
  7. EDATE=$EMDDIR/bin/e_date
  8. DBIF=$EMDDIR/informix/bin/dbaccess
  9. DBNAME=enlighten
  10. TBLNAME=audit_log_tbl
  11.  
  12. totalinput=$#
  13. managednum=0
  14. usernum=0
  15. guinum=0
  16. argmt=0
  17. value=0
  18. where=0
  19. flag=0
  20.  
  21. case $OSNAME in
  22.     AIX)
  23.             AWK=nawk;;
  24.     HP-UX)
  25.             AWK=awk;;
  26.     IRIX)
  27.             AWK=nawk;;
  28.     IRIX64)
  29.             AWK=nawk;;
  30.     SunOS)
  31.             AWK=nawk;;    
  32. esac    
  33.  
  34. incrargmt() {
  35.     argmt=`expr $argmt + 1`;
  36. }
  37.  
  38. incrvalue() {
  39.     value=`expr $value + 1`;
  40. }
  41.  
  42. addparen() {
  43.     sqlstmt="$sqlstmt)";
  44. }
  45.  
  46. appendstmt() {
  47.     if [ $where -eq 1 ]; then
  48.         sqlstmt="$sqlstmt and"
  49.     else
  50.         where=1
  51.         sqlstmt="$sqlstmt where"            
  52.     fi;
  53. }
  54.  
  55. createlist() {
  56.  
  57.     if [ $1 -eq 1 ]; then
  58.         sqlstmt="$sqlstmt,"
  59.     elif [ "$2" = "guinum" ];then
  60.         guinum=1
  61.         sqlstmt="$sqlstmt guihost in ("
  62.     elif [ "$2" = "managednum" ]; then
  63.         managednum=1
  64.         sqlstmt="$sqlstmt targethost in ("
  65.     elif [ "$2" = "usernum" ]; then
  66.         usernum=1
  67.         sqlstmt="$sqlstmt usr in ("
  68.     fi
  69. }
  70.  
  71. while [ $# -gt 0 ]
  72. do
  73.     case $1 in
  74.         -from)
  75.             arg=-from
  76.             incrargmt;;
  77.         -to)
  78.             arg=-to
  79.             incrargmt;;
  80.         -guihost)
  81.             arg=-guihost
  82.             incrargmt;;
  83.         -managedhost)
  84.             arg=-managedhost
  85.             incrargmt;;
  86.         -dsmuser)
  87.             arg=-dsmuser
  88.             incrargmt;;
  89.         *)
  90.             case $arg in
  91.                 -from)
  92.                     fromtime=$fromtime" $1";;
  93.                 -to)
  94.                     totime=$totime" $1";;
  95.                 -guihost)
  96.                     guihost=$guihost" $1";;
  97.                 -managedhost)
  98.                     managedhost=$managedhost" $1";;
  99.                 -dsmuser)
  100.                     dsmuser=$dsmuser" $1";;
  101.             esac;;
  102.     esac
  103.     shift
  104. done
  105.  
  106. sqlstmt='delete from '$TBLNAME 
  107.  
  108. if [ "$fromtime" ]; then
  109.     if [ \( "$fromtime" = " Beginning" \) -o \( "$fromtime" = " beginning" \) ]; then
  110.         incrvalue
  111.     else 
  112.         fromempty=`$EDATE -s $fromtime` 
  113.         if [ "$fromempty" ]; then
  114.             incrvalue    
  115.             appendstmt
  116.             sqlstmt="$sqlstmt timestamp >= $fromempty"
  117.         fi
  118.     fi
  119. fi
  120.  
  121.  
  122. if [ "$totime" ]; then
  123.     if [ \( "$totime" = " Now" \) -o \( "$totime" = " now" \) ]; then
  124.         incrvalue
  125.     else
  126.         toempty=`$EDATE -s $totime`
  127.         if [ "$toempty" ]; then
  128.             incrvalue
  129.             appendstmt
  130.             sqlstmt="$sqlstmt timestamp <= $toempty"
  131.         fi
  132.     fi
  133. fi
  134. if [ "$guihost" ]; then
  135.     incrvalue
  136.     appendstmt
  137.     for GH in $guihost
  138.     do
  139.         createlist $guinum guinum
  140.         sqlstmt="$sqlstmt '$GH'"
  141.     done
  142.     addparen
  143. fi
  144. if [ "$managedhost" ]; then
  145.     incrvalue
  146.     appendstmt
  147.     for MH in $managedhost
  148.     do
  149.         createlist $managednum managednum
  150.         sqlstmt="$sqlstmt '$MH'"
  151.     done
  152.     addparen
  153. fi
  154. if [ "$dsmuser" ]; then
  155.     incrvalue
  156.     appendstmt
  157.     for USER in $dsmuser 
  158.     do
  159.         createlist $usernum usernum    
  160.         sqlstmt="$sqlstmt '$USER'"
  161.     done
  162.     addparen
  163. fi
  164. if [ $where -eq 0 ]; then
  165.     sqlstmt="$sqlstmt where timestamp <> 0"
  166. fi
  167.  
  168.  
  169. if [ $argmt -eq 0 ]; then
  170.     if [ $value -eq 0 ]; then
  171.         if [ $totalinput -gt 0 ]; then
  172.             flag=1
  173.         fi
  174.     fi
  175. fi
  176.  
  177.  
  178. if [ \( $argmt -ne $value \) -o \( $flag -eq 1 \) ]; then
  179.     echo ""
  180.     echo "usage:"
  181.     echo "e_rm_audit_events    [-from time-string | beginning]"
  182.     echo "            [-to time-string | now]"
  183.     echo "            [-guihost hostname]"
  184.     echo "            [-managedhost hostname]"
  185.     echo "            [-dsmuser username]" 
  186.     exit 1
  187. fi
  188.  
  189. name=`id | grep root`
  190. sudb="su - dbenl"
  191.  
  192. if [ "$name" ]; then
  193. echo "$sqlstmt" | $sudb -c "$DBIF $DBNAME - 2>&1" | $AWK ' 
  194. $3 ~ /deleted./ {
  195.     printf("%d row(s) deleted from audit log.\n", $1);
  196. }'
  197.  
  198. else
  199.     echo "Root permission required to run script."
  200.     exit 1
  201. fi
  202.